package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.ReportDao;
import com.itheima.entity.Result;
import com.itheima.pojo.LineModel;
import com.itheima.pojo.SetMealReport;
import com.itheima.service.ReportService;
import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.*;

@Service(version = "1.0.0", interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportDao reportDao;

    @Override
    public Result getMemberReport() {

        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -12);
        ArrayList<String> list = new ArrayList<>();

        for (int i = 0; i < 12; i++) {
            Date time = calendar.getTime();
            list.add(new SimpleDateFormat("yyyy-MM").format(time));
            calendar.add(Calendar.MONTH, 1);
        }
        ArrayList<Integer> arrayList = new ArrayList<>();

        for (String month : list) {
            Integer count = reportDao.getMemberReport(month);
            arrayList.add(count);
        }

        LineModel lineModel = new LineModel();
        lineModel.setXAxis(list);
        lineModel.setYAxis(arrayList);
        return Result.success(lineModel);
    }

    @Override
    public Result getSetMealReport() {
        List<SetMealReport> list = reportDao.getSetMealReport();
        System.out.println(list);
        return Result.success(list);
    }
}
